package com.cqc.multiimageselector01;

import android.content.Intent;
import android.media.ExifInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.List;

import me.nereo.multi_image_selector.MultiImageSelector;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private Button btn1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = (Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Multi image selector form an Activity
                MultiImageSelector.create()
                        .start(MainActivity.this, 100);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100) {
            if (resultCode == RESULT_OK) {
                // 获取返回的图片列表
                List<String> paths = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
                // 处理你自己的逻辑 ....
                for (int i = 0; i < paths.size(); i++) {
                    try {
                        ExifInterface exif = new ExifInterface(paths.get(i));

                        String TAG_APERTURE = exif.getAttribute(ExifInterface.TAG_APERTURE);
                        String TAG_DATETIME = exif.getAttribute(ExifInterface.TAG_DATETIME);
                        String TAG_EXPOSURE_TIME = exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
                        String TAG_FLASH = exif.getAttribute(ExifInterface.TAG_FLASH);
                        String TAG_FOCAL_LENGTH = exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
                        String TAG_IMAGE_LENGTH = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
                        String TAG_IMAGE_WIDTH = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
                        String TAG_ISO = exif.getAttribute(ExifInterface.TAG_ISO);
                        String TAG_MAKE = exif.getAttribute(ExifInterface.TAG_MAKE);
                        String TAG_MODEL = exif.getAttribute(ExifInterface.TAG_MODEL);
                        String TAG_ORIENTATION = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
                        String TAG_WHITE_BALANCE = exif.getAttribute(ExifInterface.TAG_WHITE_BALANCE);

                        Log.i(TAG, "光圈值:" + TAG_APERTURE);
                        Log.i(TAG, "拍摄时间:" + TAG_DATETIME);
                        Log.i(TAG, "曝光时间:" + TAG_EXPOSURE_TIME);
                        Log.i(TAG, "闪光灯:" + TAG_FLASH);
                        Log.i(TAG, "焦距:" + TAG_FOCAL_LENGTH);
                        Log.i(TAG, "图片高度:" + TAG_IMAGE_LENGTH);
                        Log.i(TAG, "图片宽度:" + TAG_IMAGE_WIDTH);
                        Log.i(TAG, "ISO:" + TAG_ISO);
                        Log.i(TAG, "设备品牌:" + TAG_MAKE);
                        Log.i(TAG, "设备型号:" + TAG_MODEL);
                        Log.i(TAG, "旋转角度:" + TAG_ORIENTATION);
                        Log.i(TAG, "白平衡:" + TAG_WHITE_BALANCE);
                    } catch (Exception ee) {
                        Toast.makeText(getApplication(), "The date does not exit", Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    }
}
